package router

import (
	v1 "saas-app/app/api/v1"
	"saas-app/app/middleware"

	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
)

// InitializeRouters 初始化总路由
func InitializeRouters() {
	InitUserRouter() // 用户路由
	// g.Log().Info(g.I18n().Translate(`{#Prefix} {#router} {#register} {#success}`, "zh-CN"))
}

func InitUserRouter() {
	s := g.Server()

	s.Use(middleware.MiddlewareErrorHandler)
	s.Use(middleware.CORS)
	// 某些浏览器直接请求favicon.ico文件，特别是产生404时
	s.SetRewrite("/favicon.ico", "/resource/image/favicon.ico")

	s.Group("/api", func(group *ghttp.RouterGroup) {

		group.GET("/draw", v1.Draw)
		group.GET("/test", v1.Test)

		group.POST("/login", v1.Login)
		group.POST("/signup", v1.SignUp)
		group.GET("/GetFiveData2", v1.GetFiveData2)
		group.POST("/zuowen/info", v1.GetZuowenInfo)
		group.POST("/peotry/info", v1.GetPeotryInfo)
		group.GET("/city/:parent_id", v1.GetDistrictsList)
		group.GET("/wechat/verification", v1.Verification)

		group.Group("/user", func(group *ghttp.RouterGroup) {
			group.Middleware(middleware.JWTAuth)
			group.GET("/info", v1.UserInfo)
			group.POST("/signout", v1.Signout)
			group.POST("/update", v1.UpdateUserInfo)
		})

		group.Group("/school", func(group *ghttp.RouterGroup) {

			group.Middleware(middleware.JWTAuth)
			group.GET("/list", v1.GetSchoolList)
			group.POST("/create", v1.CreateSchool)

			group.Middleware(middleware.SchoolAuth)
			group.GET("/campus/list", v1.GetCampusList)
			group.GET("/campus/simple/list", v1.GetCampusSimpleList)
			group.POST("/campus/update", v1.UpdateCampus)
			group.POST("/campus/create", v1.CreateCampus)
		})

		group.Group("/teacher", func(group *ghttp.RouterGroup) {
			group.Middleware(middleware.JWTAuth)
			group.GET("/list", v1.GetTeacherList)
			group.POST("/update", v1.UpdateTeacher)
			group.POST("/create", v1.CreateTeacher)
		})

		group.Group("/class", func(group *ghttp.RouterGroup) {

			group.Middleware(middleware.JWTAuth)
			group.Middleware(middleware.CampusAuth)

			group.GET("/list", v1.GetClassList)
			group.GET("/simple/list", v1.GetClassSimpleList)
			group.GET("/info", v1.GetClassInfo)
			group.POST("/create", v1.CreateClass)

			group.Group("/", func(group *ghttp.RouterGroup) {
				group.Middleware(middleware.ClassAuth)
				group.POST("/update", v1.UpdateClass)
			})

			group.Group("/member", func(group *ghttp.RouterGroup) {

				group.GET("/list", v1.GetClassMemeberList)

				group.Middleware(middleware.ClassAuth)
				group.POST("/create", v1.CreateClassMemeber)
				group.POST("/leave", v1.LeaveClassMember)
			})

		})

		group.Group("/student", func(group *ghttp.RouterGroup) {
			group.Middleware(middleware.JWTAuth)
			group.GET("/list", v1.GetStudentList)
			group.POST("/update", v1.UpdateStudent)
			group.POST("/create", v1.CreateStudent)
			group.POST("/card/add", v1.CreateStudentCard)
			group.GET("/card/list", v1.GetStudentCardList)
			group.GET("/course", v1.StudentCourselist)
			group.POST("/attendance", v1.Attendance)
		})

		group.Group("/subject", func(group *ghttp.RouterGroup) {
			group.Middleware(middleware.JWTAuth)
			group.GET("/list", v1.GetSubjectList)
			group.POST("/update", v1.UpdateSubject)
			group.POST("/create", v1.CreateSubject)
		})

		group.Group("/card", func(group *ghttp.RouterGroup) {

			group.Middleware(middleware.JWTAuth)
			group.Middleware(middleware.CampusAuth)

			group.GET("/list", v1.GetCardList)
			group.GET("/simple/list", v1.GetCardList)
			group.POST("/create", v1.CreateCard)

			group.Middleware(middleware.CardAuth)
			group.POST("/update", v1.UpdateCard)
		})

		group.Group("/upload", func(group *ghttp.RouterGroup) {
			group.Middleware(middleware.JWTAuth)
			group.POST("/file", v1.UploadImageFile)
		})

		group.Group("/zuowen", func(group *ghttp.RouterGroup) {
			group.Middleware(middleware.JWTAuth)
			group.POST("/sync", v1.SaveZuowen)
			group.GET("/list", v1.GetZuowenList)
			group.GET("/lastid", v1.GetZuowenLastId)
		})

		group.Group("/peotry", func(group *ghttp.RouterGroup) {
			group.Middleware(middleware.JWTAuth)
			group.POST("/sync", v1.CreatePeotry)
			group.GET("/lastid", v1.GetPeotryLastId)
			group.GET("/list", v1.GetPeotryList)
		})

		group.Group("/course", func(group *ghttp.RouterGroup) {
			group.Middleware(middleware.JWTAuth)
			group.Middleware(middleware.SchoolAuth)
			group.GET("/list", v1.GetCourseList)
			group.POST("/check", v1.CheckCourse)
			group.POST("/add", v1.AddCourse)
		})

		group.Group("/role", func(group *ghttp.RouterGroup) {
			group.Middleware(middleware.JWTAuth)
			group.Middleware(middleware.CampusAuth)
			group.GET("/list", v1.GetRoleList)
			group.POST("/create", v1.CreateRole)
			group.POST("/update", v1.UpdateRole)
			group.POST("/delete", v1.RoleDelete)
			group.POST("/power/update", v1.UpdateRolePower)
		})

		group.Group("/power", func(group *ghttp.RouterGroup) {
			group.Middleware(middleware.JWTAuth)
			group.Middleware(middleware.CampusAuth)
			group.GET("/", v1.PowerList)
		})

		group.Group("/redis", func(group *ghttp.RouterGroup) {
			group.GET("/test", v1.TestRedis)
		})
	})
}
